package com.chapter03;

import com.bdqn.util.JDBCUtils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Test01_Insert {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        Scanner input = new Scanner(System.in);
        System.out.print("输入年级编号：");
        int gradeId = input.nextInt();

        System.out.print("输入年级名称：");
        String gradeName = input.next();


        // todo 第一步：获取连接对象
        Connection connection = JDBCUtils.getConnection();

        // todo 第二步：创建statement对象
        Statement statement = connection.createStatement();

        // todo 第三步：调用statement对象的executeUpdate（）方法
//        String sql = "insert into grade VALUES(103,'研一'),(104,'研二');";
        String sql = "insert into grade VALUES(" + gradeId + ",'" + gradeName + "');";
        int i = statement.executeUpdate(sql);
        System.out.println("受影响的行数：" + i);
        if (i > 0) {
            System.out.println("添加成功！");
        } else {
            System.out.println("添加失败！");
        }

        // todo 第四步：释放连接相关资源
        statement.close();
        connection.close();
    }
}
